package leetcode_周赛._2021._202112._19;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/12/19 11:04
 */
public class _5958 {
    public static void main(String[] args) {
        System.out.println(new _5958().getDescentPeriods(new int[]{12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 4, 3, 10, 9, 8, 7}));
    }

    public long getDescentPeriods(int[] prices) {
        int len = prices.length;
        if (prices.length ==  1) return 1;
        long[] pre = new long[len + 1];
        pre[0] = 0;
        for (int i = 1; i <= len; i++) pre[i] = i + pre[i - 1];
        long ans = 0;
        int cnt = 1;
        for (int i = 1; i < len; i++) {
            if (prices[i - 1] - prices[i] == 1) ++cnt;
            else {
                ans += pre[cnt];
                cnt = 1;
            }
        }
        return ans + pre[cnt];
    }

}
